package com.yuba.front.controller.collect;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.yuba.common.idempotent.annotation.RepeatSubmit;
import com.yuba.common.log.annotation.Log;
import com.yuba.common.web.core.BaseController;
import com.yuba.common.mybatis.core.page.PageQuery;
import com.yuba.common.core.domain.R;
import com.yuba.common.core.validate.AddGroup;
import com.yuba.common.core.validate.EditGroup;
import com.yuba.common.log.enums.BusinessType;
import com.yuba.common.excel.utils.ExcelUtil;
import com.yuba.front.domain.vo.CollectFishSiteVo;
import com.yuba.front.domain.bo.CollectFishSiteBo;
import com.yuba.front.service.ICollectFishSiteService;
import com.yuba.common.mybatis.core.page.TableDataInfo;

/**
 * 钓场收藏管理
 *
 * @author modakai
 * @date 2024-12-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/collect/CollectFishSite")
public class CollectFishSiteController extends BaseController {

    private final ICollectFishSiteService collectFishSiteService;

    /**
     * 查询钓场收藏管理列表
     */
    @SaCheckPermission("collect:CollectFishSite:list")
    @GetMapping("/list")
    public TableDataInfo<CollectFishSiteVo> list(CollectFishSiteBo bo, PageQuery pageQuery) {
        return collectFishSiteService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出钓场收藏管理列表
     */
    @SaCheckPermission("collect:CollectFishSite:export")
    @Log(title = "钓场收藏管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CollectFishSiteBo bo, HttpServletResponse response) {
        List<CollectFishSiteVo> list = collectFishSiteService.queryList(bo);
        ExcelUtil.exportExcel(list, "钓场收藏管理", CollectFishSiteVo.class, response);
    }

    /**
     * 获取钓场收藏管理详细信息
     *
     * @param fishSiteId 主键
     */
    @SaCheckPermission("collect:CollectFishSite:query")
    @GetMapping("/{fishSiteId}")
    public R<CollectFishSiteVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long fishSiteId) {
        return R.ok(collectFishSiteService.queryById(fishSiteId));
    }

    /**
     * 新增钓场收藏管理
     */
    @SaCheckPermission("collect:CollectFishSite:add")
    @Log(title = "钓场收藏管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CollectFishSiteBo bo) {
        return toAjax(collectFishSiteService.insertByBo(bo));
    }

    /**
     * 修改钓场收藏管理
     */
    @SaCheckPermission("collect:CollectFishSite:edit")
    @Log(title = "钓场收藏管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CollectFishSiteBo bo) {
        return toAjax(collectFishSiteService.updateByBo(bo));
    }

    /**
     * 删除钓场收藏管理
     *
     * @param fishSiteIds 主键串
     */
    @SaCheckPermission("collect:CollectFishSite:remove")
    @Log(title = "钓场收藏管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fishSiteIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] fishSiteIds) {
        return toAjax(collectFishSiteService.deleteWithValidByIds(List.of(fishSiteIds), true));
    }
}
